package drone.basis.util ;

import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;

public class CurrencyUtil
{

	// 雅虎汇率查询
	// public static String lookup(String curNo) {
	// String url =
	// "http://download.finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=" +
	// curNo + "CNY=x";
	// String result = new String(HttpUtil.call(url));
	// String[] res = result.split(",");
	// String r = res[1].replaceAll("\"", "");
	// return r;
	// }

	// 极速汇率查询
	public static String lookup (
			String curNo
		) throws Exception
	{
		String url = "http://op.juhe.cn/onebox/exchange/currency?key=1c5ab4d0d383f1f18bd1e40ade5d7852&from=" + curNo + "&to=CNY" ;
		JSONObject resultObject = JSONObject.parseObject ( HttpUtil.get ( url , null ) ) ;
		JSONArray resultarr = resultObject.getJSONArray ( "result" ) ;
		JSONObject resultobj = resultarr.getJSONObject ( 0 ) ;
		String rate = resultobj.getString ( "result" ) ;
		return rate ;
	}

	public static void main (
			String [ ] args
		) throws Exception
	{
		System.out.println ( lookup ( "MXN" ) ) ;

	}
}
